package com.pinapel.aixml.models.xml;

import java.util.ArrayList;
import java.util.List;

public class NodeID {
	/*
	 * Members
	 */
	private  List<Integer> mSequence;
	
	/**
	 * @author karloz
	 * @param  sequence 
	 */
	public NodeID(List<Integer> sequence){
		this.mSequence = sequence;
	}
	
	public NodeID(int[] sequence){
		this.mSequence = new ArrayList<Integer>();
		for (int i=0;i<sequence.length;i++){
			this.mSequence.add(sequence[i]);			
		}
	}
	
	/**
	 * @author karloz
	 * @param  void
	 */	
	public NodeID getTail(){		
		return new NodeID(this.mSequence.subList(1, this.mSequence.size()));
	}
	
	/**
	 * @author karloz 
	 * @return first sequence integer 
	 */
	public int getHead(){
		return this.mSequence.get(0);
	}
	
	/**
	 * @author karloz
	 * @return List<Integer>
	 */
	
	public List<Integer> getList(){
		return this.mSequence;
	}
	
	public int getLast(){
		return this.mSequence.get(this.mSequence.size()-1);
	}
	
	public String toString(){
		StringBuilder tmp = new StringBuilder();
		tmp.append("[");
		for (Integer i : this.mSequence){
			tmp.append(" "+i);
		}
		tmp.append(" ]");
		return tmp.toString();
	}
	
	public NodeID clone(){
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		for (int i=0;i<this.mSequence.size();i++){
			tmp.add(this.mSequence.get(i));
		}
		return new NodeID(tmp);
	}
	
	public boolean equals(NodeID nid){
		if (nid.getList().size()!=this.getList().size()){
			return false;
		}else{ 
			return (nid.getList().equals(this.getList()));			
		}
	}
}
